<!--
 * @Description: 寒假校园精英PK赛报名列表
 * @Author: Li Yujie
 * @Date: 2021/01/21
 * @Last Modified by: Li Yujie
 * @Last Modified time: 2021/01/21
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    报名列表
                </div>
            </div>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        用户编号/手机号
                    </p>
                    <el-input
                        placeholder="请输入用户编号或者手机号"
                        v-model="filterData.keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        学校名称
                    </p>
                    <el-cascader
                        v-model="filterData.school_name"
                        placeholder="请选择学校"
                        :options="school_tree"
                        filterable
                        clearable
                        :show-all-levels="false"
                        size="medium"
                        change-on-select
                        expand-trigger="click"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                        :props="{
                            label: 'name',
                            value: 'name',
                            children: 'children',
                        }"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        活动状态
                    </p>
                    <el-select
                        v-model="filterData.act_status"
                        clearable
                        filterable
                        placeholder="全部"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in statusList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        是否被取消过资格
                    </p>
                    <el-select
                        v-model="filterData.deny_status"
                        clearable
                        filterable
                        placeholder="全部"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            label="全部"
                            value=""
                        />
                        <el-option
                            label="是"
                            :value="1"
                        />
                        <el-option
                            label="否"
                            :value="0"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        报名时间
                    </p>
                    <el-date-picker
                        v-model="dateTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="medium"
                        style="width: 400px"
                        value-format="timestamp"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                </div>
            </div>
            <!--筛选-->

            <!-- table -->
            <el-table
                :data="tableData"
                height="100%"
                style="width: 100%;"
                ref="tempLateName"
                class="data-table"
                v-loading="tableLoading"
            >
                <el-table-column
                    label="序号"
                    align="center"
                    width="80"
                    type="index"
                />
                <el-table-column
                    prop="true_name"
                    label="用户昵称"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    label="精英等级"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div v-if="scope.row.agent_level !== -1">E{{ scope.row.agent_level }}</div>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="phone"
                    label="联系方式"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="school_name"
                    label="学校"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="activity_title"
                    label="活动名称"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    label="报名时间"
                    align="center"
                    width="200"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.apply_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="活动状态"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div v-if="scope.row.act_status === 0">未开始</div>
                        <div v-if="scope.row.act_status === 1">进行中</div>
                        <div v-if="scope.row.act_status === -1">已结束</div>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="school_apply_count"
                    label="该校报名人数"
                    show-overflow-tooltip
                    align="center"
                />
                <el-table-column
                    prop="activity_apply_count"
                    label="已报名人数"
                    show-overflow-tooltip
                    align="center"
                />
                <el-table-column
                    label="是否被取消资格"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        <div v-if="scope.row.deny_status === 0">否</div>
                        <div v-if="scope.row.deny_status === 1">是</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="操作"
                    align="left"
                    width="180"
                >
                    <template slot-scope="scope">
                        <div class="option-btn-group">
                            <el-button
                                type="text"
                                size="medium"
                                :disabled="scope.row.act_deny_enable === 0"
                                @click="cancelQualifications(scope.row, 'all')"
                            >
                                淘汰
                            </el-button>
                            <el-button
                                type="text"
                                size="medium"
                                :disabled="scope.row.series_deny_enable === 0"
                                @click="cancelQualifications(scope.row)"
                            >
                                本档期资格取消
                            </el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <!-- /table -->

            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
    </div>
</template>

<script>
import { back } from '@/mixin/back';

export default {
    name: 'PkApplyList',
    mixins: [back],
    components: {},
    data() {
        return {
            filterData: {
                // 用户信息
                keyword: '',
                // 学校名称
                school_name: [],
                // 活动状态
                act_status: '',
                // 是否被取消过资格
                deny_status: '',
                // 报名时间
                start_time: '',
                end_time: ''
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            dateTimeRange: [],
            // 审核类型
            statusList: [
                {label: '全部', value: ''},
                {label: '未开始', value: 0},
                {label: '进行中', value: 1},
                {label: '已结束', value: -1},
            ],
            school_tree: []
        };
    },
    computed: {},
    watch: {
        dateTimeRange(value) {
            this.filterData.start_time = value ? value[0] / 1000 : '';
            this.filterData.end_time = value ? value[1] / 1000 : '';
            this.getTableData(1);
        }
    },

    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '寒假校园精英PK赛'}, {title: '报名列表'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
        this.getSchoolTree();
    },

    methods: {

        /**
         * @description 获取省/市/学校三级联动
         */
        getSchoolTree () {
            this.$post('/student/local_info%5Cschool_tree',{},resp => {
                if (resp.code === 1) {
                    this.school_tree = resp.data.tree;
                }
            });
        },

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {

            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            params.school_name = params.school_name.length > 0 ? params.school_name[2]: '';

            this.$post('/student/pk%5Cget_apply_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                }
                this.tableLoading = false;
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 本档期资格取消
         * @param row
         * @param type - all淘汰
         */
        cancelQualifications(row, type) {
            if(!this.authResult.auth_cancel) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            this.$confirm(`${type === 'all' ? '淘汰后，该精英将不能参与本次活动' : '本档期资格取消后，再次报名数据重新计算'}`, '友情提示', {
                confirmButtonText: '确认',
                cancelButtonText: '我再想想',
                type: 'warning',
                center: true
            }).then(() => {
                let params = {
                    student_no: row.student_no,
                    activity_no: row.activity_no,
                    series_no: type === 'all' ? 'sa_activity' : row.current_series_no
                };

                this.$post('/student/pk%5Capp_deny', params, res => {
                    if (res.code === 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            type: 'success',
                            message: '操作成功'
                        });
                    } else {
                        this.$notify({
                            title: '提示',
                            type: 'warning',
                            message: res.msg
                        });
                    }
                });
            });
        }
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        padding: 24px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin-left: 12px;
                margin-bottom: 24px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            margin-top: 24px;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 24px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
            }
        }

        // 表格
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
        }
        /* 分页 */

        .pagination-wrapper {
            padding-top: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    .info-dialog-wrapper {
        padding: 3px 22px;
        /deep/ .el-form-item {
            margin-bottom: 0;
        }
        /deep/ .el-form-item__content {
            line-height: 30px;
            margin-top: 6px;
        }
        .close-btn {
            width: 120px;
            height: 36px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-left: 50%;
            transform: translateX(-50%);
            margin-top: 24px;
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    .el-textarea__inner {
        resize: none;
    }
}
</style>
